package com.aq.appserver.server.theme.dao;

import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import com.aq.appserver.server.theme.entity.Comment;

public interface CommentDao extends PagingAndSortingRepository<Comment, Long>, JpaSpecificationExecutor<Comment> {

	@Query("select count(distinct s.id) from Comment s  where s.themeId = ?1")
	public int getReplyNum(String id);

	@Query("select count(distinct s.id) from Comment s  where s.phoneNum = ?1")
	public int getMyReplyCount(String phoneNumber);

	@Query("select new com.aq.appserver.server.theme.entity.Comment(s.id, s.content, s.contentType, s.phoneNum, s.replyTag, s.anonymousTag, s.position, s.updateTime,"
			+ "  s.thumbUrl, a.nickName, s.voiceTime) from Comment s, Account a where s.phoneNum = a.phoneNumber and s.themeId = ?1")
	public Page<Comment> findContentByThemeId(String themeId,
			Pageable pageable);
	
	public List<Comment> findByThemeId(String themeId);
}
